package com.xxwu.springgobang.config;

import com.xxwu.springgobang.api.TestAPI;
import com.xxwu.springgobang.controller.GameController;
import com.xxwu.springgobang.controller.MatchController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
import org.springframework.web.socket.server.support.HttpSessionHandshakeInterceptor;

import javax.annotation.Resource;

@Component
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {
    @Autowired
    private TestAPI testAPI;

    @Resource
    private MatchController matchController;

    @Resource
    private GameController gameController;

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(testAPI,"/test");
        registry.addHandler(matchController,"/findMatch")
                //这里还要将用户登录时创建的Session信息放进websocket的Session中
                .addInterceptors(new HttpSessionHandshakeInterceptor());
        registry.addHandler(gameController,"/game")
                .addInterceptors(new HttpSessionHandshakeInterceptor());

    }
}
